package com.jiusit.common;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONObject;

import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;


public class SentMessage {

	/**
	 * 身份验证短信
	 * @param telphone
	 * @param code
	 * @param product
	 * @return
	 */
	public static Map<String,String> sentMsg(String message_url,String appKey,String appSecret,String template_id,String telephone,String code,String product,String signName){
		
		Map<String,String> ret = new HashMap<String,String>();
		try {
			
			TaobaoClient taobaoClient = new DefaultTaobaoClient(message_url, appKey, appSecret);
			AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
			
			Map<String, String> paramMap = new HashMap<String, String>();
			paramMap.put("code", code);
			paramMap.put("product", product);
			
			req.setSmsType("normal");
			req.setSmsFreeSignName(signName);
			req.setSmsParamString(new JSONObject(paramMap).toString());
			req.setRecNum(telephone);
			req.setSmsTemplateCode(template_id);
			AlibabaAliqinFcSmsNumSendResponse rsp = taobaoClient.execute(req);
			
			if(rsp.isSuccess()){
				ret.put("code","0");
				ret.put("msg","短信发送成功");				
			}else{
				ret.put("code","-1");
				ret.put("msg",rsp.getMsg());
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			ret.put("code","-1");
			ret.put("msg","服务器错误");
		}
		return ret;
	}
}
